package com.siterwell.push.controller;


import com.alibaba.fastjson.JSONObject;
import com.siterwell.push.controller.base.BaseController;
import com.siterwell.push.entity.ResponseModel;
import com.siterwell.push.entity.ResultEnum;
import com.siterwell.push.service.IDeviceService;
import com.siterwell.push.util.ReadUtil.FCMManager;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.logging.Logger;

@RestController
@RequestMapping("/uaa")
public class MobileUaaController extends BaseController {

    private static final Logger logger = Logger.getLogger(MobileUaaController.class.getCanonicalName());

    @Autowired
    private IDeviceService deviceService;
    /**
     * sendVerifyCode
     * @return
     * 发送邮箱验证码功能(无图形校验,用于注册和重置密码)
     */
    @RequestMapping(value = "/sendVerifyCode",method = RequestMethod.GET)
    @ResponseBody
    public Object sendVerifyCode(){

        logger.info("哈哈哈");

        return ResponseModel.getModel(ResultEnum.SUCCESS,null);
    }

    /**
     * sendFCMMessage
     * @return
     * 发送FCM推送
     */
    @RequestMapping(value = "/sendFCMMessage",method = RequestMethod.POST)
    @ResponseBody
    public Object sendFCMMessage(@RequestBody JSONObject jsonObject){

        logger.info("jsonObject："+jsonObject.toString());
        String device_id = jsonObject.getString("hw_id");

        if(StringUtils.isEmpty(device_id)){
            return ResponseModel.getModel(ResultEnum.FAILED,null);
        }



        List<String> relationList = deviceService.getRelations(device_id);
        logger.info("relationList："+relationList);
        if(relationList.size()>0){
            for (String d:relationList) {
                deviceService.sendFCMMessage(d,"注意,烟雾报警器报警","请注意烟雾报警器0000000000e0报警");
            }
        }



        return ResponseModel.getModel(ResultEnum.SUCCESS,null);
    }




}
